<template>
	<div>
		<jk-table ref="jkTable" border :data="tableData" :height="tableHeight - 40">
			<vxe-column
				v-for="(item, index) in tableColumnList"
				:key="index"
				:title="item.title"
				:align="item.align"
				:field="item.keyName"
				:sortable="item.sortable"
				:fixed="item.fixed ? item.fixed : ''"
				:min-width="item.minWidth"
				:width="item.width"
			>
				<template slot-scope="scope">
					<span v-if="item.keyName === 'fireCounts' && scope.row.fireCounts !== 0" class="link-style" @click="onSeeBtn(scope.row)">{{ scope.row[item.keyName] }}</span>
					<span v-else>{{ scope.row[item.keyName] }}</span>
				</template>
			</vxe-column>
		</jk-table>

		<detail-dialog
			:data-item="detailDialogParams"
			:dialog-state="detailDialogState"
			@on-visible-change="onVisibleChange"
		></detail-dialog>
	</div>
</template>

<script>
    import calHeight from '/src/mixins/cal-table-height';
    import getMenuColumn from '../../../../mixins/getMenuColumn';
    import { systemUserColumnConfigGet } from '@/api/system/column-config';
    import handlerCache from '../../../../mixins/handler-cache';
    import detailDialog from '../detail-dialog.vue';
    export default {
        components: { detailDialog },
        mixins: [calHeight, getMenuColumn, handlerCache],
        props: {
            tableData: {
                type: Array,
                default() {
                    return [];
                }
            },
            height: {
                type: [String, Number],
                default: 0
            },
            shiftName: {
                type: [String],
                default: ''
            }
        },
        data() {
            return {
                detailDialogParams: {},
                detailDialogState: false,
                tableColumnList: []
            };
        },
        methods: {
            onVisibleChange(e) {
                this.detailDialogState = e;
            },
            onSeeBtn(e) {
                this.detailDialogParams = {
                    machineCode: e.machineCode,
                    probeNo: e.probeNo,
                    dateRange: e.dateRange,
                    shiftName: this.shiftName
                };
                this.detailDialogState = true;
            },
            mergeColMethod({ row, _rowIndex, column, visibleData }) {
                const fields = ['processName']; // 根据字段判断数据相同的合并
                const cellValue = row[column.property];
                if (cellValue && fields.includes(column.property)) {
                    const prevRow = visibleData[_rowIndex - 1];
                    let nextRow = visibleData[_rowIndex + 1];
                    if (prevRow && prevRow[column.property] === cellValue) {
                        return { rowspan: 0, colspan: 0 };
                    } else {
                        let countRowspan = 1;
                        while (nextRow && nextRow[column.property] === cellValue) {
                            nextRow = visibleData[++countRowspan + _rowIndex];
                        }
                        if (countRowspan > 1) {
                            return { rowspan: countRowspan, colspan: 1 };
                        }
                    }
                }
            }
        },
        getMenuColumnListRequest() {
            return systemUserColumnConfigGet({ path: 'MetalAndSparkAlarmStatistics', filterShow: true }).then(res => {
                if (res.data.status === 200) {
                    console.log(res.data.res);
                    this.tableColumnList = res.data.res || [];
                }
            });
        },
        mounted() {
            this.getMenuColumnListRequest();
        }
    };
</script>
